<?php
require_once 'path.php';
MasterTemplate::setup('Inactivity email');
MasterTemplate::minimal();
Authentication::demand();

$time = NOW()-60*60*24*500;
$inactives = db_query("SELECT playerID, plHandle, email FROM `players` where `loginStamp` <= $time AND access LIKE '1;%' AND `inactiveMail` = 0");

$mailSubjects = array('Star Wars Combine - Inactivity Email',
					  'Inactivity Email - Star Wars Combine',
					  'SWCombine - Inactivity Email',
					  'Inactivity Email - SWCombine',
					  'www.swcombine.com - Inactivity Email',
					  'Inactivity Email - www.swcombine.com',
					  'SWCombine - New Features!',
					  'New Features at www.swcombine.com!');

foreach($inactives as $inactive) {
	$hash = md5('combine' . $inactive->email . 'combine');
	if($inactive->plHandle == '') { $plHandle = 'former member'; } else { $plHandle = $inactive->plHandle; };
	
	$mailText = <<<EOT
	Dear "$plHandle",
	We've missed having you as part of our community here at the <a href='http://www.swcombine.com'>Star Wars Combine</a>. We thought you might be interested to learn about some of the latest developments.
	<ul>
	<li>Did you know that <strong>NPC combat is live</strong>? Now you can strike down groups of NPCs or creatures for XP and a chance at rare drops!</li>
	<li><strong>Player-vs-player combat</strong> is now in beta stage on the planet Derra! Head over and show off your combat prowess alone or with some squads of NPCs. Player-run tournaments are held annually for a chance at big prizes.</li>
	<li>The galaxy is full of <strong>new creatures and races</strong>! We now have 86 playable races, and almost 50 different breeds of creatures that can be captured and leveled to fight alongside you.</li>
	<li>We've given the <strong>galaxy a makeover</strong>! We've implemented hundreds of new visible and hidden systems, some hidden new races that you can choose to switch to once they are discovered. Previously existing planets and systems have been moved to their canon locations as well.</li>
	<li><strong>Galactic wonders</strong>! Some of your favourite canon locations can now be visited for an achievement or a special souvenir.</li>
	</ul>
	These are only some of the latest highlights. Stop by the <a href='http://www.swcombine.com'>Star Wars Combine</a> to find out what else we've been working on and to say hello to some of your old friends.
	From all of us here on the Star Wars Combine development team, we look forward to seeing you again!
	
	
	<span style='font-size: 11px; color: #999999;'>You are receiving this annual digest because you have an inactive account with the Star Wars Combine. Never want to hear from us again? <a href='" . DARKNESS_PATHWEB . "/unsubscribe.php?hash=" . $hash . "'>[unsubscribe]</a>.</span>.
EOT;
	
	EmailUtil::sendMail($inactive->email,array_rand($mailSubject),$mailText);
	db_query("UPDATE `players` WHERE `playerID` = '$player->playerID' SET `inactiveMail` = 1");
	echo 'Email sent to:'.$inactive->playerID.' - '.$plHandle.'<br />';
}